package org.hcyspartnoc.luoxin.controller.chat;

import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import org.hcyspartnoc.luoxin.common.core.AjaxResult;
import org.hcyspartnoc.luoxin.common.core.PageBean;
import org.hcyspartnoc.luoxin.common.core.annotation.Log;
import org.hcyspartnoc.luoxin.common.core.annotation.PreAuthorize;
import org.hcyspartnoc.luoxin.common.core.enums.BusinessType;
import org.hcyspartnoc.luoxin.common.exception.chat.ChatSessionNoteException;
import org.hcyspartnoc.luoxin.common.exception.framework.AuthException;
import org.hcyspartnoc.luoxin.pojo.po.chat.ChatSessionNotePo;
import org.hcyspartnoc.luoxin.pojo.vo.chat.ChatSessionNoteVo;
import org.hcyspartnoc.luoxin.service.chat.IChatSessionNoteService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/chat/note")
public class ChatSessionNoteController {
    @Resource
    private IChatSessionNoteService chatSessionNoteService;

    @Log(title = "聊天·手记·查询·分页·token", businessType = BusinessType.OTHER)
    @PreAuthorize(auth = "chat:note:query:page:token", descr = "分页获取咨询手记")
    @GetMapping("/query/page/token")
    public AjaxResult queryPageByToken(@Min(value = 1, message = "当前页不能小于1")
                                       @RequestParam(defaultValue = "1") int currentPage,
                                       @Min(value = PageBean.MIN_PAGE_SIZE, message = "每页大小" + PageBean.MIN_PAGE_SIZE + "-" + PageBean.MAX_PAGE_SIZE)
                                       @Max(value = PageBean.MAX_PAGE_SIZE, message = "每页大小" + PageBean.MIN_PAGE_SIZE + "-" + PageBean.MAX_PAGE_SIZE)
                                       @RequestParam(defaultValue = "5") int pageSize) {
        PageBean<ChatSessionNotePo, ChatSessionNoteVo> pageBean = chatSessionNoteService.queryPageByToken(currentPage, pageSize);
        return AjaxResult.success(pageBean);
    }

    @Log(title = "聊天·手记·查询·id", businessType = BusinessType.OTHER)
    @PreAuthorize(auth = "chat:note:query:id", descr = "通过id获取手记")
    @GetMapping("/query/{noteId:\\d+}")
    public AjaxResult queryById(@PathVariable Long noteId) throws AuthException, ChatSessionNoteException {
        ChatSessionNoteVo chatSessionNoteVo = chatSessionNoteService.queryById(noteId);
        return AjaxResult.success(chatSessionNoteVo);
    }
}
